package tetris.rlpark_wrapper;

import rlpark.plugin.rltoys.algorithms.functions.states.Projector;
import rlpark.plugin.rltoys.math.vector.RealVector;
import rlpark.plugin.rltoys.math.vector.implementations.BVector;

@SuppressWarnings("serial")
public class TableProjector implements Projector{
  private final int size[];
  private final BVector projection;
  public TableProjector(int size[]) {
    this.size = size;
    int projectionSize = 1;
    for (int i = 0; i < this.size.length; i++)
      projectionSize *= this.size[i];
    projection = new BVector(projectionSize);
  }

  public int vectorSize() {
    return projection.size;
  }

  @Override
  public double vectorNorm() {
    return 1;
  }

  @Override
  public RealVector project(double[] obs) {
    projection.clear();
    if (obs != null) {
      assert(obs.length == this.size.length);
      int index = 0;
      int multiplier = 1;
      for (int i = 0; i < obs.length; i++) {
        index += obs[i]*multiplier;
        multiplier *= this.size[i]; 
      }
      projection.setOn((int)index);
    }
    return projection;
  }

}
